<?php

/**
 * A download utility to allow for more flexibility in naming and storing files
 *
 * @author		Jason Orrill <jorrill@uga.edu>
 */

Class Framework_Util_Download {

	public static function getFile( $theFile, $filename, $type='application/x-download', $disposition='attachment') {
	
		$_output = null ;

		if( file_exists( $theFile )) {

			// required for IE, otherwise Content-disposition is ignored
			if(ini_get('zlib.output_compression')) {
				ini_set('zlib.output_compression', 'Off');
			}

			header("Pragma: public");
			header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); // some day in the past
			header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
			header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
			header("Cache-Control: private",false);
			header("Content-type: $type");
			header("Content-Disposition: $disposition; filename=$filename");
			header("Content-Transfer-Encoding: binary");
			header("Content-Length: ".@filesize($theFile));
			set_time_limit(0);
			@readfile($theFile) or die("File not found."); 
			$_output = true ;

		} else {
			$msg = "File not found: $theFile" ;
			$_output = Framework_ErrorHandler::raiseError( $msg, __METHOD__."::".__LINE__ ) ;
		}

		return $_output ;

	}


}

?>
